package elec;

import static java.lang.Math.signum;
import static mathUtils.VecMath.vecMag;
import static mathUtils.VecMath.vecScale;
import static mathUtils.VecMath.vecSub;
import processing.core.PApplet;
import tennos.Flake;

public class ElectroFlake extends Flake implements Electric {

	float charge;

	public ElectroFlake(PApplet p) {
		super(p);
	}
	public ElectroFlake(PApplet p, float m, float c, float r, float px, float py, float vx, float vy) {
		super(p, m ,r, px, py, vx, vy);
		charge = c;
	}

	public static int electricDimension = 3;
	
	public float charge() {return charge;}
	public float electricRho() {return 0;}

	public float[] eFieldAt(float[] x, float bigK) {
		float e[] = x.clone();
		vecSub(e, position(), e);
		float r = vecMag(e);
		vecScale(e, bigK*charge()/((float) java.lang.Math.pow(r, electricDimension)));
		return e;
	}
	public float[] eFieldAt(float[] x) {return eFieldAt(x, 1f);}
	public float[] eForceOn(Electric a, float bigK) {
		float f[];
		f = eFieldAt(a.position());
		vecScale(f, a.charge());
		return f;
	}

	public void draw() {
		parent.stroke(250f*0.5f*(1+signum(charge)), 250f*0.5f*(1-signum(charge)), 0f);
		parent.strokeWeight(0);
		parent.fill(250f*0.5f*(1+signum(charge)), 250f*0.5f*(1-signum(charge)), 0f);
		parent.ellipse(position()[0], position()[1], radius/2, radius/2);
	}
	
}
